package cc.ilzy.mall.product.controller;

import cc.ilzy.mall.api.controller.IProductController;
import cc.ilzy.mall.model.pojo.Product;
import cc.ilzy.mall.model.vo.ProductVO;
import cc.ilzy.mall.product.service.IProductService;
import cc.ilzy.mall.utils.ApiResponse;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ilzy
 * @since 2025-07-09
 */
@RestController
public class ProductController implements IProductController {
    @Autowired
    private IProductService productService;

    @Override
    public ApiResponse<Page<Product>> pageProductList(int page, int size) {
        Page<Product> ipage = productService.page(new Page<>(page, size));
        return ApiResponse.success(ipage);
    }

    @Override
    public ApiResponse<ProductVO> productDetail(Integer productId) {
        Product product = productService.getById(productId);
        ProductVO vo = BeanUtil.toBean(product, ProductVO.class);
        return ApiResponse.success(vo);
    }
}
